package com.yiduo.outpost.core.model.result;

import org.springframework.http.HttpStatus;

/**
 * 自定义状态码枚举类
 */
public enum ResultCodeEnum {

    SUCCESS(200, HttpStatus.OK, "请求成功"),
    FAILURE(400, HttpStatus.UNAUTHORIZED, "error.rest.unauthorized"),
    BAD_REQUEST(401, HttpStatus.BAD_REQUEST, "error.rest.methodArgumentNotValid"),
    SENTINEL_EXCEPTION4(HttpStatus.UPGRADE_REQUIRED.value(), HttpStatus.UPGRADE_REQUIRED, "升级请求"),

    TOO_MANY_REQUESTS(HttpStatus.TOO_MANY_REQUESTS.value(), HttpStatus.TOO_MANY_REQUESTS, "请求太多！限流了"),
    SYSTEM_ERROR(500, HttpStatus.INTERNAL_SERVER_ERROR, "系统异常"),
    NOT_FOUND(404, HttpStatus.NOT_FOUND, "找不到页面"),
    NON_EXISTENT(404, HttpStatus.NOT_FOUND, "non-existent"),
    UNSUPPORTED_MEDIA_TYPE(415, HttpStatus.UNSUPPORTED_MEDIA_TYPE, "不支持的媒体类型"),
    GATEWAY_DOWNSTREAM_ERROR_INFO_FORMAT_ERROR(10001, HttpStatus.INTERNAL_SERVER_ERROR, "下游服务返回的错误信息格式错误"),
    METHOD_NOT_ALLOWED(405, HttpStatus.METHOD_NOT_ALLOWED, "请求方式不支持"),

    RestException(10000, HttpStatus.BAD_REQUEST, "error.rest.exception"),
    LoginTimeOutException(10001, HttpStatus.INTERNAL_SERVER_ERROR, "error.rest.LoginTimeOutException");


    private int code;
    private String message;

    private HttpStatus httpStatus;

    ResultCodeEnum() {
    }

    ResultCodeEnum(int code, HttpStatus httpStatus, String message) {
        this.code = code;
        this.message = message;
        this.httpStatus = httpStatus;
    }

    ResultCodeEnum(int code, String message) {
        this.code = code;
        this.message = message;
        this.httpStatus = HttpStatus.OK;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    @Override
    public String toString() {
        return "ResultCodeEnum [code=" + code + ", message=" + message + ", httpStatus=" + httpStatus + "]";
    }

}
